package com.VitalFit.controller;

import com.VitalFit.annotation.LoginUser;
import com.VitalFit.model.enums.ResultEnum;
import com.VitalFit.model.dto.AppointmentDTO;
import com.VitalFit.model.dto.FitnessPlanDTO;
import com.VitalFit.model.vo.AppointmentVO;
import com.VitalFit.model.vo.FitnessPlanVO;
import com.VitalFit.model.vo.ResultVO;
import com.VitalFit.service.serviceImpl.CustomerServiceImpl;
import com.VitalFit.util.ResultVOUtil;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/customer")
@RequiredArgsConstructor
@Validated
public class CustomerController {

    private final CustomerServiceImpl customerServiceImpl;

    @PreAuthorize("hasRole('ROLE_CUSTOMER')")
    @PostMapping("/appointment")
    public ResultVO<AppointmentVO> makeAppointment(@LoginUser Long userId, @RequestBody @Valid AppointmentDTO appointmentDTO) {
        // 预约教练路由
        return ResultVOUtil.buildResult(ResultEnum.ORDER_SUCCESS, customerServiceImpl.makeAppointment(userId, appointmentDTO));
    }

    @PreAuthorize("hasRole('ROLE_CUSTOMER')")
    @PostMapping("/fitness_plan")
    public ResultVO<FitnessPlanVO> purchaseFitnessPlan(@LoginUser Long userId, @RequestBody @Valid FitnessPlanDTO fitnessPlanDTO) {
        // 购买训练计划路由
        return ResultVOUtil.buildResult(ResultEnum.PURCHASE_SUCCESS, customerServiceImpl.purchaseFitnessPlan(userId, fitnessPlanDTO));
    }

}


